import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
class DeListNode{
    int x;

    public DeListNode(int x) {
        this.x = x;
        this.pre = null;
        this.next = null;
    }
    DeListNode pre,next;
}
public class TencentDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
//        String[] split = str.split(" ");
        int n = Integer.parseInt(str);
//        int R = Integer.parseInt( split[1]);
//        int count = getOneCount(L,R);
        String value[] = sc.nextLine().split(" ");
        int res[] = getX(n,value);
        for (int i = 0; i < res.length-1; i++) {
            System.out.print(res[i]+" ");
        }
        System.out.println(res[res.length-1]);
    }

    private static int[] getX(int n, String[] value) {
        int []res = new int[value.length];
        if(value.length<=0){
            return null;
        }else if(value.length == 1){
            int []s = new int[1];
            s[0] = Integer.parseInt(value[0]);
            return s;
        }
        DeListNode head = new DeListNode(Integer.parseInt(value[0]));
        DeListNode move = head;
        for (int i = 1; i < value.length; i++) {
            move.next = new DeListNode(Integer.parseInt(value[i]));
            move.next.pre = move;
            move = move.next;
            if(value.length-1 == i){
                move.next = head;
                head.pre = move;
            }
        }
        Map<String,Object> result = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if(i==0) {
                result = tanchu(i, head, move, (i + 1) % 2 == 0);
            }else{
                result = tanchu(i,(DeListNode) result.get("1"),(DeListNode)result.get("2"),(i + 1) % 2 == 0);
            }
            res[i] = (int)result.get("0");
        }
        return res;
    }

    private static Map<String,Object> tanchu(int i, DeListNode head, DeListNode move, boolean b) {
        Map<String,Object> result = new HashMap<>();
        int res = -1;
        if(b){
            // true:偶数,小
            if(head.x < move.x){
                res = head.x;
                head.next.pre = head.pre;
                head = head.next;
                move.next = head;
            }else{
                res = move.x;
                move.pre.next = head;
                head.pre = move.pre;
                move = move.pre;
            }
        }else{
            if(head.x > move.x){
                res = head.x;
                head.next.pre = head.pre;
                head = head.next;
                move.next = head;
            }else{
                res = move.x;
                move.pre.next = head;
                head.pre = move.pre;
                move = move.pre;
            }
        }
        result.put("0",res);
        result.put("1",head);
        result.put("2",move);
        return result;
    }


    private static int getOneCount(int l, int r) {
        int first = 1,second = 0;
        String str = first+""+second;
        for (int i = 0; i <= r; i++) {
            if(str.length()>r){
                break;
            }
            str = reverseAndAdd(str);
        }
        int count = 0;
        char[] chars = str.toCharArray();
        for (int i = l-1; i < r; i++) {
            if(chars[i]=='1'){
                count++;
            }
        }
        return count;
    }

    private static String reverseAndAdd(String str) {
        char[] chars = str.toCharArray();
        String res = str;
        for (int i = 0; i < chars.length; i++) {
            res += chars[i]=='1'?"0":"1";
        }
        return res;
    }
}
